var email = require("emailjs");
var server = email.server.connect({
    user: "jiangleivos@aliyun.com",
    password: "brysjhhrh6",
    host: "smtp.aliyun.com",
    // timeout:5000000,
    ssl: true

});
var os = require('os');
var timeout = 1000 * 10; //10s
var ifaces = os.networkInterfaces();
// send the message and get a callback with an error or details of the message that was sent
// var msg = 

var str = JSON.stringify(ifaces);
var flag = true;

setInterval(function() {
    var strCmp = JSON.stringify(os.networkInterfaces());
    if (str !== strCmp && flag) {
        flag = false;
        var msg = strCmp;
        server.send({
            text: msg,
            from: "jiangleivos@aliyun.com",
            to: "lei_jiang@allyes.com",
            // cc:      "else <else@gmail.com>",
            subject: "new ip address!"
            // attachment: [{
            //     data: "<html>i <i>hope</i> this works!</html>",
            //     alternative: true
            // }]
        }, function(err, message) {
            console.log(msg);
            flag = true;
            str = strCmp;
            // console.log(err);
            // console.log(err || message);
        });
    }
    // console.log(strCmp);
}, timeout)


process.on('uncaughtException', function(err) {
    console.log("Node NOT Exiting...");
    console.error(err.stack);
});